"""Follow-up reminder schemas."""

from __future__ import annotations

from datetime import datetime
from pydantic import BaseModel, Field, ConfigDict


class FollowUpReminderBase(BaseModel):
    """跟进提醒基础Schema."""

    lead_id: int = Field(..., description="客户ID", gt=0)
    visitor_sheet_id: int | None = Field(None, description="访客单ID")
    reminder_type: str = Field(..., description="提醒类型: auto/manual")
    trigger_reason: str | None = Field(None, description="触发原因", max_length=200)
    reminder_time: datetime = Field(..., description="提醒时间")
    assigned_to: int = Field(..., description="分配给谁（用户ID）", gt=0)
    notes: str | None = Field(None, description="备注")


class FollowUpReminderCreate(FollowUpReminderBase):
    """创建跟进提醒请求."""

    pass


class FollowUpReminderUpdate(BaseModel):
    """更新跟进提醒请求（全字段可选）."""

    reminder_time: datetime | None = None
    assigned_to: int | None = None
    notes: str | None = None
    status: str | None = Field(None, description="状态: pending/sent/completed/cancelled")


class FollowUpReminderOut(FollowUpReminderBase):
    """跟进提醒输出Schema."""

    id: int
    status: str = Field(..., description="状态: pending/sent/completed/cancelled")
    sent_at: datetime | None = Field(None, description="邮件发送时间")
    completed_at: datetime | None = Field(None, description="完成时间")
    created_at: datetime
    updated_at: datetime

    model_config = ConfigDict(from_attributes=True)


class FollowUpReminderWithLead(FollowUpReminderOut):
    """跟进提醒输出Schema（包含客户信息）."""

    lead_name: str = Field(..., description="客户姓名")
    lead_phone: str = Field(..., description="客户手机号")
    assignee_name: str = Field(..., description="分配对象姓名")
    assignee_email: str = Field(..., description="分配对象邮箱")

    model_config = ConfigDict(from_attributes=True)


class FollowUpReminderListOut(BaseModel):
    """跟进提醒列表输出."""

    total: int = Field(..., description="总数")
    items: list[FollowUpReminderWithLead] = Field(..., description="提醒列表")
    page: int = Field(1, description="当前页码")
    page_size: int = Field(50, description="每页数量")


class TodayTasksOut(BaseModel):
    """今日待办任务输出."""

    pending_count: int = Field(..., description="待处理数量")
    overdue_count: int = Field(..., description="逾期数量")
    tasks: list[FollowUpReminderWithLead] = Field(..., description="任务列表")
